package com.hgy.carsb.service;

import com.hgy.carsb.entity.UnitAnalysisDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UnitAnalysisService {

    @Autowired
    private InfoService infoService;

    public UnitAnalysisDetail getUnitDetail(int year, int month, String code1, String code2, String prefix){
        String thisMonth = infoService.getRatio(year, month, code1, code2, prefix);
        String lastMonth;
        if (month==1){
            lastMonth = infoService.getRatio(year-1, 12, code1, code2, prefix);
        }else {
            lastMonth = infoService.getRatio(year, month-1, code1, code2, prefix);
        }
        UnitAnalysisDetail unitAnalysisDetail = new UnitAnalysisDetail(thisMonth, lastMonth);
        return unitAnalysisDetail;
    }
}
